home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1_3 / sys / amiga / winreq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-03  |  16.5 KB  |  712 lines

  1. /*    SCCS Id: @(#)winreq.c    3.1    93/04/02 */
  2. /* Copyright (c) Gregg Wonderly, Naperville, Illinois,  1991,1992,1993. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "amiga:windefs.h"
  6. #include "amiga:winext.h"
  7. #include "amiga:winproto.h"
  8.  
  9. #define GADBLUEPEN      2
  10. #define GADREDPEN       3
  11. #define GADGREENPEN     4
  12. #define GADCOLOKAY      5
  13. #define GADCOLCANCEL    6
  14. #define GADCOLSAVE      7
  15.  
  16. UBYTE UNDOBUFFER[300];
  17. SHORT BorderVectors1[] = { 0,0, 57,0, 57,11, 0,11, 0,0 };
  18. struct Border Border1 = { -1,-1, 3,0,JAM1, 5, BorderVectors1, NULL };
  19. struct IntuiText IText1 = { 3,0,JAM2, 4,1, NULL, (UBYTE *)"Cancel", NULL };
  20. struct Gadget Gadget2 = {
  21.     NULL, 9,15, 56,10, NULL, RELVERIFY, BOOLGADGET, (APTR)&Border1,
  22.     NULL, &IText1, NULL, NULL, 1, NULL
  23. };
  24. UBYTE StrStringSIBuff[300];
  25. struct StringInfo StrStringSInfo = {
  26.     StrStringSIBuff, UNDOBUFFER, 0, 300, 0, 0,0,0,0,0, 0, 0, NULL
  27. };
  28. SHORT BorderVectors2[] = { 0,0, 439,0, 439,11, 0,11, 0,0 };
  29. struct Border Border2 = { -1,-1, 3,0,JAM1, 5, BorderVectors2, NULL };
  30. struct Gadget String = {
  31.     &Gadget2, 77,15, 438,10, NULL, RELVERIFY+STRINGCENTER, STRGADGET,
  32.     (APTR)&Border2, NULL, NULL, NULL, (APTR)&StrStringSInfo, 2, NULL
  33. };
  34.  
  35. #define StrString \
  36.    ((char *)(((struct StringInfo *)(String.SpecialInfo))->Buffer))
  37.  
  38. struct NewWindow StrWindow = {
  39.     57,74, 526,31, 0,1, GADGETUP+CLOSEWINDOW+ACTIVEWINDOW+VANILLAKEY,
  40.     WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH,
  41.     &String, NULL, NULL, NULL, NULL, 5,5, 0xffff,0xffff, CUSTOMSCREEN
  42. };
  43.  
  44. #include "colorwin.c"
  45.  
  46. void
  47. EditColor()
  48. {
  49.     extern const char *configfile;
  50.     int i, done = 0, okay = 0;
  51.     long code, qual, class;
  52.     register struct Gadget *gd, *dgad;
  53.     register struct Window *nw;
  54.     register struct IntuiMessage *imsg;
  55.     register struct PropInfo *pip;
  56.     register struct Screen *scrn;
  57.     long aidx;
  58.     int msx, msy;
  59.     int curcol = 0, drag = 0;
  60.     int bxorx, bxory, bxxlen, bxylen;
  61.     UWORD colors[ 1L << DEPTH ];
  62.     static int once = 0;
  63.  
  64.     bxylen = Col_NewWindowStructure1.Height -
  65.                 ( Col_BluePen.TopEdge + Col_BluePen.Height + 6 );
  66.     bxxlen = Col_BluePen.Width;
  67.     bxorx = Col_BluePen.LeftEdge;
  68.     bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2;
  69.     scrn = HackScreen;
  70.  
  71.     if( !once )
  72.     {
  73.     SetBorder( &Col_Okay );
  74.     SetBorder( &Col_Cancel );
  75.     SetBorder( &Col_Save );
  76.     once = 1;
  77.     }
  78.  
  79.     for( i = 0; i < (1L << DEPTH); ++i )
  80.     {
  81.     colors[ i ] = GetRGB4( scrn->ViewPort.ColorMap, i );
  82.     }
  83.  
  84.     Col_NewWindowStructure1.Screen = scrn;
  85. #ifdef  INTUI_NEW_LOOK
  86.     if( IntuitionBase->LibNode.lib_Version >= 37 )
  87.     {
  88.     ((struct PropInfo *)Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK;
  89.     ((struct PropInfo *)Col_RedPen.SpecialInfo)->Flags |=  PROPNEWLOOK;
  90.     ((struct PropInfo *)Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK;
  91.     }
  92. #endif
  93.     nw = OpenWindow( (void *)&Col_NewWindowStructure1 );
  94.     PrintIText( nw->RPort, &Col_IntuiTextList1, 0, 0 );
  95.  
  96.     DrawCol( nw, curcol, colors );
  97.     while( !done )
  98.     {
  99.     WaitPort( nw->UserPort );
  100.  
  101.     while( imsg = (struct IntuiMessage * )GetMsg( nw->UserPort ) )
  102.     {
  103.         gd = (struct Gadget *)imsg->IAddress;
  104.         code = imsg->Code;
  105.         class = imsg->Class;
  106.         qual = imsg->Qualifier;
  107.         msx = imsg->MouseX;
  108.         msy = imsg->MouseY;
  109.  
  110.         ReplyMsg( (struct Message *)imsg );
  111.  
  112.         switch( class )
  113.         {
  114.         case VANILLAKEY:
  115.             if( code == 'v' && qual == AMIGALEFT )
  116.             okay = done = 1;
  117.             else if( code == 'b' && qual == AMIGALEFT )
  118.             okay = 0, done = 1;
  119.             else if( code == 'o' || code == 'O' )
  120.             okay = done = 1;
  121.             else if( code == 'c' || code == 'C' )
  122.             okay = 0, done = 1;
  123.             break;
  124.  
  125.         case CLOSEWINDOW:
  126.             done = 1;
  127.             break;
  128.  
  129.         case GADGETUP:
  130.             drag = 0;
  131.             if( gd->GadgetID == GADREDPEN ||
  132.                         gd->GadgetID == GADBLUEPEN ||
  133.                         gd->GadgetID == GADGREENPEN )
  134.             {
  135.             pip = (struct PropInfo *)gd->SpecialInfo;
  136.             aidx = pip->HorizPot / (MAXPOT/15);
  137.             if( gd->GadgetID == GADREDPEN )
  138.             {
  139.                 colors[ curcol ] =
  140.                 ( colors[ curcol ] & ~0xf00 ) | (aidx << 8);
  141.                 LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  142.             }
  143.             else if( gd->GadgetID == GADBLUEPEN )
  144.             {
  145.                 colors[ curcol ] =
  146.                     ( colors[ curcol ] & ~0xf ) | aidx;
  147.                 LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  148.             }
  149.             else if( gd->GadgetID == GADGREENPEN )
  150.             {
  151.                 colors[ curcol ] =
  152.                 ( colors[ curcol ] & ~0x0f0 ) | (aidx << 4);
  153.                 LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  154.             }
  155.             DispCol( nw, curcol, colors );
  156.             }
  157.             else if( gd->GadgetID == GADCOLOKAY )
  158.             {
  159.             done = 1;
  160.             okay = 1;
  161.             }
  162.             else if( gd->GadgetID == GADCOLSAVE )
  163.             {
  164.                 FILE *fp, *nfp;
  165.                 char buf[ 300 ], nname[ 300 ], oname[ 300 ];
  166.             int once = 0;
  167.  
  168.                 fp = fopen( configfile, "r" );
  169.             if( !fp )
  170.             {
  171.                 pline( "can't find NetHack.cnf" );
  172.                             break;
  173.             }
  174.  
  175.             strcpy( oname, dirname( configfile ) );
  176.             if( oname[ strlen(oname)-1 ] != ':' )
  177.             {
  178.                 sprintf( nname, "%s/New_NetHack.cnf", oname );
  179.                 strcat( oname, "/" );
  180.                 strcat( oname, "Old_NetHack.cnf" );
  181.             }
  182.             else
  183.             {
  184.                 sprintf( nname, "%sNew_NetHack.cnf", oname );
  185.                 strcat( oname, "Old_NetHack.cnf" );
  186.             }
  187.  
  188.                 nfp = fopen( nname, "w" );
  189.                 if( !nfp )
  190.                 {
  191.                 pline( "can't write to New_NetHack.cnf" );
  192.                             fclose( fp );
  193.                             break;
  194.                         }
  195.             while( fgets( buf, sizeof( buf ), fp ) )
  196.             {
  197.                 if( strncmp( buf, "PENS=", 5 ) == 0 )
  198.                 {
  199.                 once = 1;
  200.                     fputs( "PENS=", nfp );
  201.                     for( i = 0; i < (1l << DEPTH); ++i )
  202.                     {
  203.                         fprintf( nfp, "%03x", colors[i] );
  204.                         if(( i + 1 ) < (1l << DEPTH))
  205.                             putc( '/', nfp );
  206.                     }
  207.                         putc( '\n', nfp );
  208.                 }
  209.                 else
  210.                 {
  211.                     fputs( buf, nfp );
  212.                 }
  213.             }
  214.  
  215.             /* If none in the file yet, now write it */
  216.             if( !once )
  217.             {
  218.                         fputs( "PENS=", nfp );
  219.                         for( i = 0; i < (1l << DEPTH); ++i )
  220.                         {
  221.                             fprintf( nfp, "%03x", colors[i] );
  222.                             if(( i + 1 ) < (1l << DEPTH))
  223.                                 putc( ',', nfp );
  224.                         }
  225.                             putc( '\n', nfp );
  226.             }
  227.             fclose( fp );
  228.             fclose( nfp );
  229.             unlink( oname );
  230.             if( filecopy( configfile, oname ) == 0 )
  231.                 filecopy( nname, configfile );
  232.             done = 1;
  233.             okay = 1;
  234.             }
  235.             else if( gd->GadgetID == GADCOLCANCEL )
  236.             {
  237.             done = 1;
  238.             okay = 0;
  239.             }
  240.             break;
  241.  
  242.         case GADGETDOWN:
  243.             drag = 1;
  244.             dgad = gd;
  245.             break;
  246.  
  247.         case MOUSEMOVE:
  248.             if( !drag )
  249.             break;
  250.             pip = (struct PropInfo *)dgad->SpecialInfo;
  251.             aidx = pip->HorizPot / (MAXPOT/15);
  252.             if( dgad->GadgetID == GADREDPEN )
  253.             {
  254.             colors[ curcol ] =
  255.                 ( colors[ curcol ] & ~0xf00 ) | (aidx << 8);
  256.             LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  257.             }
  258.             else if( dgad->GadgetID == GADBLUEPEN )
  259.             {
  260.             colors[ curcol ] = ( colors[ curcol ] & ~0xf ) | aidx;
  261.             LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  262.             }
  263.             else if( dgad->GadgetID == GADGREENPEN )
  264.             {
  265.             colors[ curcol ] =
  266.                 ( colors[ curcol ] & ~0x0f0 ) | (aidx << 4);
  267.             LoadRGB4( &scrn->ViewPort, colors, 1l << DEPTH );
  268.             }
  269.             DispCol( nw, curcol, colors );
  270.             break;
  271.  
  272.         case MOUSEBUTTONS:
  273.             if( code == SELECTDOWN )
  274.             {
  275.             if( msy > bxory && msy < bxory + bxylen - 1 &&
  276.                 msx > bxorx && msx < bxorx + bxxlen - 1 )
  277.             {
  278.                 curcol = ( msx - bxorx )/(bxxlen / (1l << DEPTH));
  279.                 DrawCol( nw, curcol, colors );
  280.             }
  281.             }
  282.             break;
  283.         }
  284.     }
  285.     }
  286.  
  287.     if( okay )
  288.     {
  289.     for( i = 0; i < ( 1L << DEPTH ); ++i )
  290.         flags.amii_curmap[ i ] = colors[ i ];
  291.     }
  292.  
  293.     LoadRGB4( &scrn->ViewPort, flags.amii_curmap, 1L << DEPTH );
  294.     CloseWindow( nw );
  295. }
  296.  
  297. char *dirname( str )
  298.     char *str;
  299. {
  300.     char *t, c;
  301.     static char dir[ 300 ];
  302.  
  303.     t = strrchr( str, '/' );
  304.     if( !t )
  305.     t = strrchr( str, ':' );
  306.     if( !t )
  307.     t = str;
  308.     else
  309.     {
  310.         c = *t;
  311.         *t = 0;
  312.         strcpy( dir, str );
  313.         *t = c;
  314.     }
  315.     return( dir );
  316. }
  317.  
  318. char *basename( str )
  319.     char *str;
  320. {
  321.     char *t;
  322.  
  323.     t = strrchr( str, '/' );
  324.     if( !t )
  325.     t = strrchr( str, ':' );
  326.     if( !t )
  327.     t = str;
  328.     else
  329.     ++t;
  330.     return( t );
  331. }
  332.  
  333. filecopy( from, to )
  334.     char *from, *to;
  335. {
  336.     char *buf;
  337.     int i = 0;
  338.  
  339.     buf = malloc( strlen(to) + strlen(from) + 20 );
  340.     if( buf )
  341.     {
  342.         sprintf( buf, "c:copy \"%s\" \"%s\" clone", from, to );
  343.  
  344.         /* Check SysBase instead?  Shouldn't matter  */
  345. #ifdef    INTUI_NEW_LOOK
  346.     if( IntuitionBase->LibNode.lib_Version >= 37 )
  347.         i = System( buf, NULL );
  348.     else
  349. #endif
  350.         Execute( buf, NULL, NULL );
  351.         free( buf );
  352.     }
  353.     else
  354.     {
  355.         return( -1 );
  356.     }
  357.     return( i );
  358. }
  359.  
  360. /* The colornames, and the default values for the pens */
  361. static struct
  362. {
  363.     char *name, *defval;
  364. } colnames[] =
  365. {
  366.     "Black","(000)",
  367.     "White","(fff)",
  368.     "Brown","(830)",
  369.     "Cyan","(7ac)",
  370.     "Green","(181)",
  371.     "Magenta","(c06)",
  372.     "Blue","(23e)",
  373.     "Red","(c00)",
  374. };
  375.  
  376. void
  377. DrawCol( w, idx, colors )
  378.     struct Window *w;
  379.     int idx;
  380.     UWORD *colors;
  381. {
  382.     int bxorx, bxory, bxxlen, bxylen;
  383.     int i, incx, incy, r, g, b, yh = 4;
  384.     long mflags;
  385.  
  386.     if( w->WScreen->Height > 300 )
  387.     yh *= 2;
  388.     bxylen = Col_NewWindowStructure1.Height - (Col_Okay.Height + txheight + 8) -
  389.             ( Col_BluePen.TopEdge + Col_BluePen.Height + 10 ) + yh;
  390.     bxxlen = Col_BluePen.Width - 2;
  391.     bxorx = Col_BluePen.LeftEdge + 1;
  392.     bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2;
  393.  
  394.     incx = bxxlen / (1L << DEPTH);
  395.     incy = bxylen - 2;
  396.  
  397.     SetAPen( w->RPort, C_WHITE );
  398.     SetBPen( w->RPort, C_BLACK );
  399.     SetDrMd( w->RPort, JAM2 );
  400.     RectFill( w->RPort, bxorx, bxory, bxorx + bxxlen - 1, bxory + bxylen );
  401.  
  402.     SetAPen( w->RPort, C_BLACK );
  403.     RectFill( w->RPort, bxorx+2, bxory+1,
  404.                     bxorx + bxxlen - 4, bxory + bxylen - 1);
  405.  
  406.     for( i = 0; i < (1L << DEPTH); ++i )
  407.     {
  408.     if( i == idx )
  409.     {
  410.         SetAPen( w->RPort, scrnpens[ SHINEPEN ] );
  411.         Move( w->RPort, bxorx + 3 + (i*incx)+0, bxory+bxylen - 1);
  412.         Draw( w->RPort, bxorx + 3 + (i*incx)+0, bxory + 1 );
  413.         Draw( w->RPort, bxorx + ((i+1)*incx)-1, bxory + 1 );
  414.  
  415.         Move( w->RPort, bxorx + 3 + (i*incx)+1, bxory+bxylen - 2);
  416.         Draw( w->RPort, bxorx + 3 + (i*incx)+1, bxory + 2 );
  417.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory + 2 );
  418.  
  419.         SetAPen( w->RPort, scrnpens[ SHINEPEN ] );
  420.         Move( w->RPort, bxorx + 3 + (i*incx)+0, bxory+bxylen - 1);
  421.         Draw( w->RPort, bxorx + ((i+1)*incx)-1, bxory+bxylen - 1);
  422.         Draw( w->RPort, bxorx + ((i+1)*incx)-1, bxory + 1 );
  423.  
  424.         Move( w->RPort, bxorx + 3 + (i*incx)+1, bxory+bxylen - 2);
  425.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory+bxylen - 2);
  426.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory + 2);
  427.     }
  428.     else
  429.     {
  430.         SetAPen( w->RPort, scrnpens[ SHINEPEN ] );
  431.         Move( w->RPort, bxorx + 3 + (i*incx)+1, bxory+bxylen - 2);
  432.         Draw( w->RPort, bxorx + 3 + (i*incx)+1, bxory + 2 );
  433.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory + 2 );
  434.         Move( w->RPort, bxorx + 3 + (i*incx)+1, bxory+bxylen - 2);
  435.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory+bxylen - 2);
  436.         Draw( w->RPort, bxorx + ((i+1)*incx)-2, bxory + 2);
  437.     }
  438.  
  439.     SetAPen( w->RPort, i );
  440.     RectFill( w->RPort, bxorx + 3 + (i*incx)+3, bxory + 4,
  441.                     bxorx + ((i+1)*incx)-4, bxory+bxylen - 4);
  442.     }
  443.  
  444.     DispCol( w, idx, colors );
  445.  
  446.     r = (colors[ idx ] & 0xf00) >> 8;
  447.     g = (colors[ idx ] & 0x0f0) >> 4;
  448.     b = colors[ idx ] & 0x00f;
  449.  
  450.     mflags = AUTOKNOB|FREEHORIZ;
  451. #ifdef  INTUI_NEW_LOOK
  452.     if( IntuitionBase->LibNode.lib_Version >= 37 )
  453.     {
  454.     mflags |= PROPNEWLOOK;
  455.     }
  456. #endif
  457.     NewModifyProp( &Col_RedPen, w, NULL, mflags, (r * MAXPOT ) / 15, 0,
  458.                                 MAXPOT/15, 0, 1 );
  459.     NewModifyProp( &Col_GreenPen, w, NULL, mflags, (g * MAXPOT ) / 15, 0,
  460.                                 MAXPOT/15, 0, 1 );
  461.     NewModifyProp( &Col_BluePen, w, NULL, mflags, (b * MAXPOT ) / 15, 0,
  462.                                 MAXPOT/15, 0, 1 );
  463. }
  464.  
  465. void
  466. DispCol( w, idx, colors )
  467.     struct Window *w;
  468.     int idx;
  469.     UWORD *colors;
  470. {
  471.     char buf[ 50 ];
  472.  
  473.     Move( w->RPort, Col_Save.LeftEdge,
  474.     Col_Save.TopEdge - 4 );
  475.     sprintf( buf, "%s=%03x default=%s%s", colnames[idx].name, colors[idx],
  476.     colnames[idx].defval,
  477.     "        "+strlen(colnames[idx].name)+1 );
  478.     SetAPen( w->RPort, C_WHITE );
  479.     SetBPen( w->RPort, 0 );
  480.     SetDrMd( w->RPort, JAM2 );
  481.     Text( w->RPort, buf, strlen( buf ) );
  482. }
  483.  
  484. void
  485. amii_setpens()
  486. {
  487.     /* If the pens are set in NetHack.cnf, we can get called before
  488.      * HackScreen has been opened...
  489.      */
  490.     if( HackScreen != NULL )
  491.     {
  492.     LoadRGB4( &HackScreen->ViewPort, flags.amii_curmap, 1L << DEPTH );
  493.     }
  494. }
  495.  
  496. /* Generate a requester for a string value. */
  497.  
  498. void amii_getlin(prompt,bufp)
  499.     const char *prompt;
  500.     char *bufp;
  501. {
  502.     getlind(prompt,bufp,0);
  503. }
  504.  
  505. /* and with default */
  506. void getlind(prompt,bufp, dflt)
  507.     const char *prompt;
  508.     char *bufp;
  509.     const char *dflt;
  510. {
  511. #ifndef TOPL_GETLINE
  512.     register struct Window *cwin;
  513.     register struct IntuiMessage *imsg;
  514.     register long class, code, qual;
  515.     register int aredone = 0;
  516.     register struct Gadget *gd;
  517.     static int once;
  518.  
  519.     *StrString = 0;
  520.     if( dflt )
  521.     strcpy( StrString, dflt );
  522.     StrWindow.Title = (UBYTE *)prompt;
  523.     StrWindow.Screen = HackScreen;
  524.  
  525.     if( !once )
  526.     {
  527.     if( bigscreen )
  528.         StrWindow.TopEdge = (HackScreen->Height/2) - (StrWindow.Height/2);
  529.     SetBorder( &String );
  530.     SetBorder( &Gadget2 );
  531.     once = 1;
  532.     }
  533.  
  534.     if( ( cwin = OpenWindow( (void *)&StrWindow ) ) == NULL )
  535.     {
  536.     return;
  537.     }
  538.  
  539.     WindowToFront( cwin );
  540.     while( !aredone )
  541.     {
  542.     WaitPort( cwin->UserPort );
  543.     while( ( imsg = (void *) GetMsg( cwin->UserPort ) ) != NULL )
  544.     {
  545.         class = imsg->Class;
  546.         code = imsg->Code;
  547.         qual = imsg->Qualifier;
  548.         gd = (struct Gadget *) imsg->IAddress;
  549.  
  550.         switch( class )
  551.         {
  552.         case VANILLAKEY:
  553.             if( code == '\033' && (qual &
  554.                 (IEQUALIFIER_LALT|IEQUALIFIER_RALT|
  555.                 IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND) ) == 0 )
  556.             {
  557.             if( bufp )
  558.             {
  559.                 bufp[0]='\033';
  560.                 bufp[1]=0;
  561.             }
  562.             aredone = 1;
  563.             }
  564.             else
  565.             {
  566.             ActivateGadget( &String, cwin, NULL );
  567.             }
  568.             break;
  569.  
  570.         case ACTIVEWINDOW:
  571.             ActivateGadget( &String, cwin, NULL );
  572.             break;
  573.  
  574.         case GADGETUP:
  575.             switch( gd->GadgetID )
  576.             {
  577.             case 2:
  578.                 aredone = 1;
  579.                 if( bufp )
  580.                 strcpy( bufp, StrString );
  581.                 break;
  582.  
  583.             case 1:
  584.                 if( bufp )
  585.                 {
  586.                 bufp[0]='\033';
  587.                 bufp[1]=0;
  588.                 }
  589.                 aredone = 1;
  590.                 break;
  591.             }
  592.             break;
  593.  
  594.         case CLOSEWINDOW:
  595.             if( bufp )
  596.             {
  597.             bufp[0]='\033';
  598.             bufp[1]=0;
  599.             }
  600.             aredone = 1;
  601.             break;
  602.         }
  603.         ReplyMsg( (struct Message *) imsg );
  604.     }
  605.     }
  606.  
  607.     CloseWindow( cwin );
  608. #else
  609.     struct amii_WinDesc *cw;
  610.     struct Window *w;
  611.     int colx, ocolx, c;
  612.     char *obufp;
  613.  
  614.     amii_clear_nhwindow( WIN_MESSAGE );
  615.     amii_putstr( WIN_MESSAGE, 0, prompt );
  616.     cw = amii_wins[ WIN_MESSAGE ];
  617.     w = cw->win;
  618.     ocolx = colx = strlen( prompt ) + 1;
  619.  
  620.     obufp = bufp;
  621.     cursor_on(WIN_MESSAGE);
  622.     while((c = WindowGetchar()) != EOF)
  623.     {
  624.     cursor_off(WIN_MESSAGE);
  625.     amii_curs( WIN_MESSAGE, colx, 0 );
  626.     if(c == '\033')
  627.     {
  628.         *obufp = c;
  629.         obufp[1] = 0;
  630.         return;
  631.     }
  632.     else if(c == '\b')
  633.     {
  634.         if(bufp != obufp)
  635.         {
  636.         bufp--;
  637.         amii_curs( WIN_MESSAGE, --colx, 0);
  638.         Text( w->RPort, "\177 ", 2 );
  639.         amii_curs( WIN_MESSAGE, colx, 0);
  640.         }
  641.         else
  642.         DisplayBeep( NULL );
  643.     }
  644.     else if( c == '\n' || c == '\r' )
  645.     {
  646.         *bufp = 0;
  647.         TOPL_NOSPACE;
  648.         amii_putstr( WIN_MESSAGE, -1, obufp );
  649.         TOPL_SPACE;
  650.         return;
  651.     }
  652.     else if(' ' <= c && c < '\177')
  653.     {
  654.         /* avoid isprint() - some people don't have it
  655.            ' ' is not always a printing char */
  656.         *bufp = c;
  657.         bufp[1] = 0;
  658.  
  659.         Text( w->RPort, bufp, 1 );
  660.         Text( w->RPort, "\177", 1 );
  661.         if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)
  662.         {
  663.         colx++;
  664.         bufp++;
  665.         }
  666.     }
  667.     else if(c == ('X'-64) || c == '\177')
  668.     {
  669.         amii_curs( WIN_MESSAGE, ocolx, 0 );
  670.         Text( w->RPort,
  671.         "                                                            ",
  672.         colx - ocolx );
  673.         amii_curs( WIN_MESSAGE, colx = ocolx, 0 );
  674.     } else
  675.         DisplayBeep( NULL );
  676.     cursor_on(WIN_MESSAGE);
  677.     }
  678.     cursor_off(WIN_MESSAGE);
  679.     *bufp = 0;
  680. #endif
  681. }
  682.  
  683. void amii_change_color( pen, val, rev )
  684.     int pen, rev;
  685.     long val;
  686. {
  687.     if( rev )
  688.     flags.amii_curmap[ pen ] = ~val;
  689.     else
  690.     flags.amii_curmap[ pen ] = val;
  691.  
  692.     if( HackScreen )
  693.     LoadRGB4( &HackScreen->ViewPort, flags.amii_curmap, 1L << DEPTH );
  694. }
  695.  
  696. char *
  697. amii_get_color_string( )
  698. {
  699.     int i;
  700.     char s[ 10 ];
  701.     static char buf[ 100 ];
  702.  
  703.     *buf = 0;
  704.     for( i = 0; i < DEPTH; ++i )
  705.     {
  706.         sprintf( s, "%s%03lx", i ? "/" : "", (long)flags.amii_curmap[ i ] );
  707.         strcat( buf, s );
  708.     }
  709.  
  710.     return( buf );
  711. }
  712.